/**
 * @ProjectName： naive-admin
 * @FileName： auto-dark
 * @Description: // 根据系统主题色自动切换
 * @Author: ellwood
 * @date: 2024/1/10 - 8:32
 * @Version: V1.0.0
 */
export const isDark = useDark()

export const toggleDark = useToggle(isDark)

export function useAutoDark() {
  const isPrefersDark = usePreferredDark()
  const appStore = useAppStore()

  watch(
    isPrefersDark,
    (isDark) => {
      // 切换暗黑模式
      if (isDark) {
        appStore.updateStyleLayout('dark')
      }
      else {
        // 切换回亮色模式
        appStore.updateStyleLayout('light')
      }
      toggleDark(isDark)
    },
    { immediate: true },
  )
}
